window.userName = $('._buryDot-userEmail')[0] ? $('._buryDot-userEmail').text() : '游客';
$(function($) {
	//轮播图
	var swiper = new Swiper('.swiper', {
			pagination: '.swiper-btn',
			loop: true,
			grabCursor: true,
			paginationClickable: true,
			autoplayDisableOnInteraction: false,
			autoplay: 1800,
			speed: 1000,
			nextButton: '.swiper-right',
			prevButton: '.swiper-left',
		})
	$(".swiper").mouseover(function () {
		swiper.stopAutoplay();
	});
    $(".swiper").mouseleave(function () {
        swiper.startAutoplay();
    });
	//TODO  埋点--精品数据 1.3
	$('._perfectData').click(function() {
		var serviceName = $(this).find('._serviceName').text().slice(1);
		var price = $(this).find('._perDataPrice').text()||'免费';
		zhuge.track('首页_精品数据', {
			'用户':userName,
			'服务名称': serviceName,
			'价格':price
		});
	});

	//TODO 埋点--热门数据 1.3
	$('._hotData').click(function() {
		var serviceName = $(this).find('._service_name').text().slice(1);
		var price = $(this).find('._hotDataPrice').text()||'免费';
		zhuge.track('首页_热门数据', {
			'用户':userName,
			'服务名称': serviceName,
			'价格':price
		});
	});

	//二级菜单 newstart

	//所有数据
	var seLevelObj = JSON.parse($('._all_index_category_list').val());
	var newseLevelObj = {};
	newseLevelObj.extend = function(obj) {
		for(var key in obj) {
			var newkey = key.split('-')[1];
			this[newkey] = obj[key];
		}
	}
	newseLevelObj.extend(seLevelObj);
	//console.log(newseLevelObj)
	/**
	 * 分类--二级分类内容
	 * @param {Object} numStr 一级分类的id值
	 */
	function secLevContent(numStr) {
		var secLevChiObj = newseLevelObj[numStr] ? newseLevelObj[numStr].children : 0;
		//console.log(secLevChiObj)
		if(secLevChiObj != '') {
			var arr = [];
			for(var a in secLevChiObj) {
				//console.log(secLevChiObj[a])
				arr.push('<a  href="/category/index.html?cid=' + numStr + '&tid=' + secLevChiObj[a].id + '">' + secLevChiObj[a].name + '</a>/');
			}
			arr[arr.length - 1] = arr[arr.length - 1].slice(0, -1);
			//console.log(arr[arr.length-1])
			var html = arr.join('');
			return html
		} else {
			return
		}
	}
	//显示
	//	$('.banner-left ul li').on('mouseenter', function() {
	//			$('._secondList').addClass('hide')
	//			$(this).next().animate({				
	//				opacity: 'show'
	//			}, 500).removeClass('hide');
	//			if(!$(this).next().html()){
	//				$(this).next().html(secLevContent($(this).find('a').attr('_idnum')))
	//			}
	//		})
	//	//隐藏
	//	$('.banner-left').on('mouseleave', function() {
	//			$('._secondList').addClass('hide')
	//		})
	//二级菜单 newend

	//热门服务商--start
	$(".develop-ul li").height($(".develop-ul li").width() / 2)
		//console.log($(".develop-ul li").width() / 2)
	window.onresize = function() {
			$(".develop-ul li").height($(".develop-ul li").width() / 2)
				//	console.log($(".develop-ul li").width() / 2)
		}
		//热门服务商--end
		//TODO 埋点 1.3
	$(document)
		.on('click', '._firCategory li', function() {
			zhuge.track('首页_分类', {
				'用户': userName,
				'分类名称': $(this).attr('md_name')
			});
		})
		.on('click', '[md_element=img]', function() {
			var cur = $(this);
			zhuge.track('首页_轮播图', {
				'用户': userName,
				'活动名称': cur.attr('alt')
			},function(){
				window.open(cur.parent().attr('href'));
			});
		})		
});